/******************************************************************************
  ------------------------搜索关注：段为创思--------------------------

******************************************************************************
*/


/* 256 个 脉冲一圈*/
#define A1 1      //引脚命名

#define B1 2
#define C1 3
#define D1 4


void setup()
{
  pinMode(A1, OUTPUT);  //设置引脚为输出引脚

  pinMode(B1, OUTPUT);
  pinMode(C1, OUTPUT);
  pinMode(D1, OUTPUT);
  Serial.begin(115200);
}

void loop()
{
  if (Serial.available() > 0) {
    int responsedata = Serial.read();
    if (responsedata != -1) {
      for (int i = 1; i <= responsedata; i++) {
        OneTime(20);
      }
    }


  }

}


void Phase_A()
{
  digitalWrite(A1, HIGH);   //A1引脚高电平
  digitalWrite(B1, LOW);
  digitalWrite(C1, LOW);
  digitalWrite(D1, LOW);
}

void Phase_B()
{
  digitalWrite(A1, LOW);
  digitalWrite(B1, HIGH);   //B1引脚高电平
  digitalWrite(C1, LOW);
  digitalWrite(D1, LOW);
}

void Phase_C()
{
  digitalWrite(A1, LOW);
  digitalWrite(B1, LOW);
  digitalWrite(C1, HIGH);   //C1引脚高电平
  digitalWrite(D1, LOW);
}

void Phase_D()
{
  digitalWrite(A1, LOW);
  digitalWrite(B1, LOW);
  digitalWrite(C1, LOW);
  digitalWrite(D1, HIGH);   //D1引脚高电平
}

void OneTime(int delayTime) {
  Phase_A();      //设置A相位
  delay(delayTime);
  Phase_B();      //设置B相位
  delay(delayTime);
  Phase_C();      //设置C相位
  delay(delayTime);
  Phase_D();      //设置D相位
  delay(delayTime);
}

void OneTimeRevese(int delayTime) {
  Phase_D();      //设置D相位
  delay(delayTime);
  Phase_C();      //设置C相位
  delay(delayTime);
  Phase_B();      //设置B相位
  delay(delayTime);
  Phase_A();      //设置A相位
  delay(delayTime);

}
